using System.Net;
using System.Security.Principal;

namespace BuildBox.Core.Server.Adapters
{
    public interface IHttpListenerContextAdapter
    {
        IHttpListenerRequestAdapter Request { get; }
        IHttpListenerResponseAdapter Response { get; }
        IPrincipal User { get; }
        IConfiguration Configuration { get; }
    }

    public class HttpListenerContextAdapter : IHttpListenerContextAdapter
    {
        private readonly HttpListenerContext _context;

        public HttpListenerContextAdapter(HttpListenerContext context, IConfiguration configuration)
        {
            _context = context;
            Configuration = configuration;
            Request = new HttpListenerRequestAdapter(context.Request, configuration);
            Response = new HttpListenerResponseAdapter(context.Response, configuration);
        }

        public IHttpListenerRequestAdapter Request { get; private set; }

        public IHttpListenerResponseAdapter Response { get; private set; }

        public IPrincipal User
        {
            get { return _context.User; }
        }

        public IConfiguration Configuration { get; private set; }
    }
}